package com.lavida.project.system.papers.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lavida.framework.web.controller.BaseController;
import com.lavida.framework.web.page.TableDataInfo;
import com.lavida.project.system.papers.domain.SubPapers;
import com.lavida.project.system.papers.service.SubPapersService;

@Controller
@RequestMapping("system/subpapers")
public class SubPapersController extends BaseController{
	private String prefix = "system/subpapers";
	@Autowired
	private SubPapersService subPapersService;
	@RequestMapping()
	public String goods() {
		return prefix + "/papers";
	}
	@RequestMapping("/list")
	@ResponseBody
	public TableDataInfo list(int id) {
		startPage();		
		List<SubPapers> selectSubPapersBySubId = subPapersService.selectSubPapersBySubId(id);
		System.out.println("========================"+id);
		return getDataTable(selectSubPapersBySubId);
	}
	
	@RequestMapping("/getSub")
	@ResponseBody
	public Map<String, Object> getSub(int id,HttpServletRequest request) {
		Map<String,Object> result = new HashMap<String, Object>();		
		SubPapers selectSub = subPapersService.selectBySubId(id);
		System.out.println("========================"+id);
		result.put("selectSub",selectSub);
		return result;
	}
	@RequestMapping("/deleteSub")
	@ResponseBody
	public String deleteSub(int id) {
		int sub = subPapersService.deleteSub(id);
		return "1";
	}
	@RequestMapping("/addSub")
	
	public String addSub(SubPapers subPapers) {
		int addsub = subPapersService.addSub(subPapers);
		return "redirect:/system/papers";
	}
	@RequestMapping("/updateSub")
	public String updateSub(SubPapers subPapers) {
		int subnumber = subPapersService.updateSub(subPapers);
		return "redirect:/system/papers";
	}
}
